import App from './App'
import {$http} from '@escook/request-miniprogram'
import store from './store/store.js'
uni.$http=$http
$http.baseUrl='https://api-hmugo-web.itheima.net'
$http.beforeRequest=function(){
  uni.showLoading({
    title:"数据加载中"
  })
}
$http.afterRequest=function(){
  uni.hideLoading()
}
//封装弹框方法
uni.$showmsg=function(title='数据请求失败',duration=1500){
  uni.showToast({
    title,
    duration,
    icon:'none'
  })
}
uni.$getlistdata=async function(url,a,c){
        const {data:res}=await uni.$http.get(...arguments[0])
        //请求数据失败 返回一个提示
        if(res.meta.status !=200) return uni.$showmsg()
        //请求成功把数据赋值给swiperlist
        if(c&&a) c[a]=res.message
        //async函数return出去可以用.then的方法通过箭头函数拿到返回值
        return res.message
      }
//把所有api都在uni的一个属性那里管理
uni.url_t={
  goodslist:'/api/public/v1/goods/search',
  homeswiper:'/api/public/v1/home/swiperdata',
  homecate:'/api/public/v1/home/catitems',
  homefloor:'/api/public/v1/home/floordata',
  catelist:'/api/public/v1/categories',
  searchq:'/api/public/v1/goods/qsearch',
  goodsdetail:'/api/public/v1/goods/detail'
}

  
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App,
  store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
    store
  }
}
// #endif